import json

from matplotlib import pyplot as plt
import numpy as np

file_name = '../wine_data_v1.json'
out_name = '../wine_data_v2.json'

a = 0
b = 0
c = 0

data_json = []
with open(file_name, "r") as f:
    file_contents = f.readlines()

for content in file_contents:
    data_json.append(json.loads(content))

data_out = []
data_max = 0
for data in data_json:
    # data_out.append(data['price'])
    if data['price'] > data_max :
        data_max = data['price']
    if data['price'] < 20:
        a = a + 1
        data['price'] = 'cheap'
    elif data['price'] <= 35:
        b = b + 1
        data['price'] = 'medium'
    else:
        c = c + 1
        data['price'] = 'expensive'
    data_out.append(json.dumps(data))

with open(out_name, "w") as f:
    for a in data_out:
        f.write(a + '\r')
        # print(data_max)
# aa = np.array(data_out)
# bins = []
# for i in range(40):
#     bins.append(i)
#
# plt.hist(aa,bins = [0,20,30,3300])
# plt.show()
# print(a,b,c)